<template>
	<view class="app-container">
		<view class="search" @click="goPath('searchFriend')">
			<image class="icon" src="../../static/images/search-1.png"></image>
			搜索好友
		</view>
		<view class="box-item" v-for="item in friendList" :key="item.name">
			<view class="tit">{{item.name}}</view>
			<cell-friend v-for="child in item.value" :key="child.id" :title="child.remark" @click.native="goTalk(child)">
				<template v-slot:left>
					<image class="icon-friend" :src="child.sysUser.avatar ? child.sysUser.avatar : defaultAvatar">
					</image>
				</template>
			</cell-friend>
		</view>
	</view>
</template>

<script>
	import CellFriend from '../../components/cell-friend.vue'
	import {
		getUser
	} from '../../utils/auth.js'
	import {
		getGroupByPinyin
	} from '../../utils/pinyin/utils.js'
	export default {
		components: {
			CellFriend
		},
		data() {
			return {
				defaultAvatar: require("../../static/images/avatar.png"),
				user: {},
				friendList: []
			}
		},
		onLoad() {
			this.user = getUser()
			this.getFriendList()
		},
		methods: {
			getFriendList() {
				this.$http('/admin/chat/friend/getFriendListByUserId/' + this.user.userInfo.userId).then(res => {
					let arr = res.data.list
					this.friendList = getGroupByPinyin(arr, 'remark')
					console.log(this.friendList);
					uni.stopPullDownRefresh()
				})
			},
			goPath(url) {
				uni.navigateTo({
					url: `/pages/friend/${url}`
				})
			},
			goTalk(item) {
				uni.navigateTo({
					url: `/pages/friend/friendMsg?friendId=${item.friendId}&nickname=${item.remark}`
				})
			}
		}
	}
</script>

<style>
	.search {
		background-color: #fff;
		height: 40px;
		color: #bfbfbf;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.tit {
		height: 30px;
		line-height: 30px;
		margin-left: 20px;
	}
</style>
